home *** CD-ROM | disk | FTP | other *** search
/ The Utilities Experience / The Utilities Experience - Volume 1.iso / software / programmers / source / chnky2plnr / chunky4.s < prev    next >
Text File  |  1978-06-29  |  7KB  |  298 lines

  1.         xdef    _chunky2planar
  2.  
  3. ; peterm/chunky4.s
  4.  
  5. ; Basically the same as peterm/chunky3.s, except use Chris Hames' idea
  6. ; of temporary FAST buffers to allow longword writes to CHIP RAM.
  7.  
  8. ;-----------------------------------------------------------------------------
  9. ; chunky2planar:    (new Motorola syntax)
  10. ;  a0 -> chunky pixels
  11. ;  a1 -> plane0 (assume other 7 planes are allocated contiguously)
  12.  
  13.  
  14. width        equ    320        ; must be a multiple of 32
  15. height        equ    200
  16. plsiz        equ    (width/8)*height
  17.  
  18. _chunky2planar:
  19.  
  20.         movem.l    d2-d7/a2-a6,-(sp)
  21.  
  22.         move.w    sp,d0
  23.         and.w    #2,d0
  24.         add.w    #32,d0        ; make room on stack for
  25.         suba.w    d0,sp        ; 32-byte longword aligned buffer
  26.         movea.l    sp,a3        ; pointed to by a3
  27.         move.w    d0,-(sp)    ; and save the allocated size
  28.         move.w    #plsiz/4,-(sp)    ; outer loop counter on stack
  29.  
  30.     iflt 4*plsiz-4-32768
  31.         adda.w    #3*plsiz,a1    ; a1 -> start of plane 3
  32.     else
  33.     iflt 2*plsiz-4-32768
  34.         adda.w    #1*plsiz,a1    ; a1 -> start of plane 1
  35.     endc
  36.     endc
  37.  
  38. ; set up register constants
  39.  
  40.         move.l    #$0f0f0f0f,d5    ; d5 = constant $0f0f0f0f
  41.         move.l    #$55555555,d6    ; d6 = constant $55555555
  42.         move.l    #$3333cccc,d7    ; d7 = constant $3333cccc
  43.         lea    (4,a3),a2    ; used for inner loop end test
  44.  
  45. ; load up address registers with buffer ptrs
  46.  
  47.         lea    (2*4,a3),a4    ; a4 -> plane2buf
  48.         lea    (2*4,a4),a5    ; a5 -> plane4buf
  49.         lea    (2*4,a5),a6    ; a6 -> plane6buf
  50.  
  51. ; main loop (starts here) processes 8 chunky pixels at a time
  52.  
  53. mainloop:
  54.  
  55. ; d0 = a7a6a5a4a3a2a1a0 b7b6b5b4b3b2b1b0 c7c6c5c4c3c2c1c0 d7d6d5d4d3d2d1d0
  56.  
  57.         move.l    (a0)+,d0    ; 12 get next 4 chunky pixels in d0
  58.  
  59. ; d1 = e7e6e5e4e3e2e1e0 f7f6f5f4f3f2f1f0 g7g6g5g4g3g2g1g0 h7h6h5h4h3h2h1h0
  60.  
  61.         move.l    (a0)+,d1    ; 12 get next 4 chunky pixels in d1
  62.  
  63. ; d2 = d0 & 0f0f0f0f
  64. ; d2 = ........a3a2a1a0 ........b3b2b1b0 ........c3c2c1c0 ........d3d2d1d0
  65.  
  66.         move.l    d0,d2        ;  4
  67.         and.l    d5,d2        ;  8 d5=$0f0f0f0f
  68.  
  69. ; d0 ^= d2
  70. ; d0 = a7a6a5a4........ b7b6b5b4........ c7c6c5c4........ d7d6d5d4........
  71.  
  72.         eor.l    d2,d0        ;  8
  73.  
  74. ; d3 = d1 & 0f0f0f0f
  75. ; d3 = ........e3e2e1e0 ........f3f2f1f0 ........g3g2g1g0 ........h3h2h1h0
  76.  
  77.         move.l    d1,d3        ;  4
  78.         and.l    d5,d3        ;  8 d5=$0f0f0f0f
  79.  
  80. ; d1 ^= d3
  81. ; d1 = e7e6e5e4........ f7f6f5f4........ g7g6g5g4........ h7h6h5h4........
  82.  
  83.         eor.l    d3,d1        ;  8
  84.  
  85. ; d2 = (d2 << 4) | d3
  86. ; d2 = a3a2a1a0e3e2e1e0 b3b2b1b0f3f2f1f0 c3c2c1c0g3g2g1g0 d3d2d1d0h3h2h1h0
  87.  
  88.         lsl.l    #4,d2        ; 16
  89.         or.l    d3,d2        ;  8
  90.  
  91. ; d0 = d0 | (d1 >> 4)
  92. ; d0 = a7a6a5a4e7e6e5e4 b7b6b5b4f7f6f5f4 c7c6c5c4g7g6g5g4 d7d6d5d4h7h6h5h4
  93.  
  94.         lsr.l    #4,d1        ; 16
  95.         or.l    d1,d0        ;  8
  96.  
  97. ; d3 = ((d2 & 33330000) << 2) | (swap(d2) & 3333cccc) | ((d2 & 0000cccc) >> 2)
  98. ; d3 = a1a0c1c0e1e0g1g0 b1b0d1d0f1f0h1h0 a3a2c3c2e3e2g3g2 b3b2d3d2f3f2h3h2
  99.  
  100.         move.l    d2,d3        ;  4
  101.         and.l    d7,d3        ;  8 d7=$3333cccc
  102.         move.w    d3,d1        ;  4
  103.         clr.w    d3        ;  4
  104.         lsl.l    #2,d3        ; 12
  105.         lsr.w    #2,d1        ; 10
  106.         or.w    d1,d3        ;  4
  107.         swap    d2        ;  4
  108.         and.l    d7,d2        ;  8 d7=$3333cccc
  109.         or.l    d2,d3        ;  8
  110.  
  111. ; d1 = ((d0 & 33330000) << 2) | (swap(d0) & 3333cccc) | ((d0 & 0000cccc) >> 2)
  112. ; d1 = a5a4c5c4e5e4g5g4 b5b4d5d4f5f4h5h4 a7a6c7c6e7e6g7g6 b7b6d7d6f7f6h7h6
  113.  
  114.         move.l    d0,d1        ;  4
  115.         and.l    d7,d1        ;  8 d7=$3333cccc
  116.         move.w    d1,d2        ;  4
  117.         clr.w    d1        ;  4
  118.         lsl.l    #2,d1        ; 12
  119.         lsr.w    #2,d2        ; 10
  120.         or.w    d2,d1        ;  4
  121.         swap    d0        ;  4
  122.         and.l    d7,d0        ;  8 d7=$3333cccc
  123.         or.l    d0,d1        ;  8
  124.  
  125. ; d2 = d1 >> 7
  126. ; d2 = ..............a5 a4c5c4e5e4g5g4b5 b4d5d4f5f4h5h4a7 a6c7c6e7e6g7g6..
  127.  
  128.         move.l    d1,d2        ;  4
  129.         lsr.l    #7,d2        ; 22
  130.  
  131. ; d0 = d1 & 55555555
  132. ; d0 = ..a4..c4..e4..g4 ..b4..d4..f4..h4 ..a6..c6..e6..g6 ..b6..d6..f6..h6
  133.  
  134.         move.l    d1,d0        ;  4
  135.         and.l    d6,d0        ;  8 d6=$55555555
  136.  
  137. ; d1 ^= d0
  138. ; d1 = a5..c5..e5..g5.. b5..d5..f5..h5.. a7..c7..e7..g7.. b7..d7..f7..h7..
  139.  
  140.         eor.l    d0,d1        ;  8
  141.  
  142. ; d4 = d2 & 55555555
  143. ; d4 = ..............a5 ..c5..e5..g5..b5 ..d5..f5..h5..a7 ..c7..e7..g7....
  144.  
  145.         move.l    d2,d4        ;  4
  146.         and.l    d6,d4        ;  8 d6=$55555555
  147.  
  148. ; d2 ^= d4
  149. ; d2 = ................ a4..c4..e4..g4.. b4..d4..f4..h4.. a6..c6..e6..g6..
  150.  
  151.         eor.l    d4,d2        ;  8
  152.  
  153. ; d1 = (d1 | d4) >> 1
  154. ; d1 = ................ a5b5c5d5e5f5g5h5 ................ a7b7c7d7e7f7g7h7
  155.  
  156.         or.l    d4,d1        ;  8
  157.         lsr.l    #1,d1        ; 10
  158.  
  159.         move.b    d1,(4,a6)    ; 12 plane 7
  160.         swap    d1        ;  4
  161.         move.b    d1,(4,a5)    ; 12 plane 5
  162.  
  163. ; d2 |= d0
  164. ; d2 = ................ a4b4c4d4e4f4g4h4 ................ a6b6c6d6e6f6g6h6
  165.  
  166.         or.l    d0,d2        ;  8
  167.  
  168.         move.b    d2,(a6)+    ;  8 plane 6
  169.         swap    d2        ;  4
  170.         move.b    d2,(a5)+    ;  8 plane 4
  171.  
  172. ; d2 = d3 >> 7
  173. ; d2 = ..............a1 a0c1c0e1e0g1g0b1 b0d1d0f1f0h1h0a3 a2c3c2e3e2g3g2..
  174.  
  175.         move.l    d3,d2        ;  4
  176.         lsr.l    #7,d2        ; 22
  177.  
  178. ; d0 = d3 & 55555555
  179. ; d0 = ..a0..c0..e0..g0 ..b0..d0..f0..h0 ..a2..c2..e2..g2 ..b2..d2..f2..h2
  180.  
  181.         move.l    d3,d0        ;  4
  182.         and.l    d6,d0        ;  8 d6=$55555555
  183.  
  184. ; d3 ^= d0
  185. ; d3 = a1..c1..e1..g1.. b1..d1..f1..h1.. a3..c3..e3..g3.. b3..d3..f3..h3..
  186.  
  187.         eor.l    d0,d3        ;  8
  188.  
  189. ; d4 = d2 & 55555555
  190. ; d4 = ..............a1 ..c1..e1..g1..b1 ..d1..f1..h1..a3 ..c3..e3..g3....
  191.  
  192.         move.l    d2,d4        ;  4
  193.         and.l    d6,d4        ;  8 d6=$55555555
  194.  
  195. ; d2 ^= d4
  196. ; d2 = ................ a0..c0..e0..g0.. b0..d0..f0..h0.. a2..c2..e2..g2..
  197.  
  198.         eor.l    d4,d2        ;  8
  199.  
  200. ; d3 = (d3 | d4) >> 1
  201. ; d3 = ................ a1b1c1d1e1f1g1h1 ................ a3b3c3d3e3f3g3h3
  202.  
  203.         or.l    d4,d3        ;  8
  204.         lsr.l    #1,d3        ; 10
  205.  
  206.         move.b    d3,(4,a4)    ; 12 plane 3
  207.         swap    d3        ;  4
  208.         move.b    d3,(4,a3)    ; 12 plane 1
  209.  
  210. ; d2 = d2 | d0
  211. ; d2 = ................ a0b0c0d0e0f0g0h0 ................ a2b2c2d2e2f2g2h2
  212.  
  213.         or.l    d0,d2        ;  8
  214.  
  215.         move.b    d2,(a4)+    ;  8 plane 2
  216.         swap    d2        ;  4
  217.         move.b    d2,(a3)+    ;  8 plane 0
  218.  
  219. ; test if stack buffers are full, loop back if not
  220.  
  221.         cmpa.l    a3,a2        ;  6
  222.         bne.w    mainloop    ; 10    total=540 (67.5 cycles/pixel)
  223.  
  224. ; move stack buffers to bitplanes (longword writes) and restore ptrs
  225.  
  226.     iflt 4*plsiz-4-32768            ; a1 points into plane 3
  227.         move.l    (a4),(a1)+        ; plane 3
  228.         move.l    (a6),(4*plsiz-4,a1)    ; plane 7
  229.         move.l    -(a6),(3*plsiz-4,a1)    ; plane 6
  230.         move.l    (a5),(2*plsiz-4,a1)    ; plane 5
  231.         move.l    -(a5),(1*plsiz-4,a1)    ; plane 4
  232.         move.l    -(a4),(-1*plsiz-4,a1)    ; plane 2
  233.         move.l    (a3),(-2*plsiz-4,a1)    ; plane 1
  234.         move.l    -(a3),(-3*plsiz-4,a1)    ; plane 0
  235.     else
  236.     iflt 2*plsiz-4-32768            ; a1 points into plane 1
  237.         move.l    (a3),(a1)+        ; plane 1
  238.         adda.l    #4*plsiz,a1
  239.         move.l    (a6),(2*plsiz-4,a1)    ; plane 7
  240.         move.l    -(a6),(1*plsiz-4,a1)    ; plane 6
  241.         move.l    (a5),(0*plsiz-4,a1)    ; plane 5
  242.         move.l    -(a5),(-1*plsiz-4,a1)    ; plane 4
  243.         suba.l    #4*plsiz,a1
  244.         move.l    (a4),(2*plsiz-4,a1)    ; plane 3
  245.         move.l    -(a4),(1*plsiz-4,a1)    ; plane 2
  246.         move.l    -(a3),(-1*plsiz-4,a1)    ; plane 0
  247.     else
  248.     iflt plsiz-32768            ; a1 points into plane 0
  249.         adda.l    #6*plsiz,a1
  250.         move.l    (a6),(plsiz,a1)        ; plane 7
  251.         move.l    -(a6),(a1)        ; plane 6
  252.         move.l    (a5),(-plsiz,a1)    ; plane 5
  253.         suba.l    #3*plsiz,a1
  254.         move.l    -(a5),(plsiz,a1)    ; plane 4
  255.         move.l    (a4),(a1)        ; plane 3
  256.         move.l    -(a4),(-plsiz,a1)    ; plane 2
  257.         suba.l    #3*plsiz,a1
  258.         move.l    (a3),(plsiz,a1)        ; plane 1
  259.         move.l    -(a3),(a1)+        ; plane 0
  260.     else
  261.         move.l    #plsiz,d0        ; a1 points into plane 0
  262.         adda.l    #7*plsiz,a1
  263.         move.l    (a6),(a1)        ; plane 7
  264.         suba.l    d0,a1
  265.         move.l    -(a6),(a1)        ; plane 6
  266.         suba.l    d0,a1
  267.         move.l    (a5),(a1)        ; plane 5
  268.         suba.l    d0,a1
  269.         move.l    -(a5),(a1)        ; plane 4
  270.         suba.l    d0,a1
  271.         move.l    (a4),(a1)        ; plane 3
  272.         suba.l    d0,a1
  273.         move.l    -(a4),(a1)        ; plane 2
  274.         suba.l    d0,a1
  275.         move.l    (a3),(a1)        ; plane 1
  276.         suba.l    d0,a1
  277.         move.l    -(a3),(a1)+        ; plane 0
  278.     endc
  279.     endc
  280.     endc
  281.  
  282. ; check if finished, go back for more
  283.  
  284.         sub.w    #1,(sp)
  285.         bne.w    mainloop
  286.  
  287. ; all done!  restore stack and return
  288.  
  289.         addq.w    #2,sp            ; remove outer loop counter
  290.         adda.w    (sp)+,sp        ; remove aligned 32-byte buffer
  291.         movem.l    (sp)+,d2-d7/a2-a6
  292.  
  293.         rts
  294.  
  295. ;-----------------------------------------------------------------------------
  296.  
  297.         end
  298.